const cluster = require('cluster');
const os = require('os');
const http = require('http');
const process = require('process');

if(cluster.isMaster){ //只有主进程才能分裂子进程
    let maxForks = os.cpus().length;
    for (let i = 0; i < maxForks; i++) {
        cluster.fork();
    }
    console.log('主进程----');
}else{
    console.log('子进程'+process.pid);
    let server = http.createServer((req,res)=>{
        if(req.url){
            console.log(process.pid+'在处理请求');
        }
        res.write('aaa'+process.pid);
        res.end();
    });
    server.listen(8080);
}
